//
//  pictureCollectionView.m
//  Recycling
//
//  Created by jzd on 2018/5/21.
//  Copyright © 2018年 宋佳. All rights reserved.
//

#import "pictureCollectionView.h"
#import "pictureFlowLayout.h"
#import "pictureCollectionViewCell.h"

@interface pictureCollectionView ()<UICollectionViewDelegate,UICollectionViewDataSource>

@end
@implementation pictureCollectionView

static NSString * const identifier = @"pictureCell";
-(void)awakeFromNib{
    [super awakeFromNib];
    self.collectionViewLayout = [[pictureFlowLayout alloc]init];
    self.delegate = self;
    self.dataSource = self;
    [self registerNib:[UINib nibWithNibName:NSStringFromClass([pictureCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:identifier];
    
}
-(void)setImages:(NSArray *)images{
    _images = images;
    [self reloadData];
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    NSInteger imgC = self.images.count;
    if (imgC <6) {
        return imgC+1;
    }else{
        return 6;
    }
    
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    [collectionView deselectItemAtIndexPath:indexPath animated:YES];
}

-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    pictureCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    
    
    if (indexPath.item<=self.images.count-1) {
        if (self.images.count == 0) {
            [cell setImg:nil];
        }else{
            UIImage *image = [self.images objectAtIndex:indexPath.item];
            [cell setImg:image];
        }
    }else{
        [cell setImg:nil];
    }
    return cell;
}

@end
